import TextFieldValue from "./showFieldValue/TextFieldValue"
import JsonSeriType from "../base/JsonSeriType"
import JsonSeriable from "../base/JsonSeriable"
import FIELD_VALUE_TYPE from "../constants/commonConstants"

export default class Field  extends JsonSeriable{
	#name;
	#code;
	#fieldValue;
	
	constructor(name,code,fieldValue){
		super();
		this.#name = name;
		this.#code = code;
		if(fieldValue){
			if(typeof(fieldValue) == "string"){
				this.#fieldValue  = new TextFieldValue(fieldValue);
			}else{
				this.#fieldValue  = fieldValue; 
			}
		}else{
			this.#fieldValue =  new TextFieldValue();
		}
		super.seriType = new JsonSeriType(FIELD_VALUE_TYPE.base.Field.code,FIELD_VALUE_TYPE.base.Field.clsPage);
	}
	
	genSeriObj(){
		
		let ret={
			"name":this.#name,
			"code":this.#code,
			"fieldValue":this.#fieldValue
		};
		return ret;
	
	}
	
	seriObj(obj){
		this.#name =  obj.name;
		this.#code =  obj.code;
		this.#fieldValue =  obj.fieldValue;
	}
	
	get name(){
		return this.#name;
	}
	
	set name(str){
		return this.#name = str;
	}
	
	get code(){
		return this.#code;
	}
	
	set code(str){
		return this.#code = str;
	}
	
	get value(){
		return this.#fieldValue.value;
	}
	
	set value(val){
		return this.#fieldValue.value = val;
	}
	
	get fieldValue(){
		return this.#fieldValue;
	}
	
	set fieldValue(fv){
		return this.#fieldValue = fv;
	}
	
}